using System;

namespace Lookstone.Data.SqlClient
{
	/// <summary>
	/// Summary description for SqlInt32Key.
	/// </summary>
	public abstract class	SqlStringKey : SqlKeyBase<string>
	{
		#region /***** Constructors *****/
		public SqlStringKey()
			: base() { InternalID = string.Empty; }

		public SqlStringKey(SqlConnectionContext context, string id)
			: base()
		{
			// Turn off the new flag on valid records
			if (id.Length > 0)
			{
				InternalID = id;
				Load(context);
				if (ID.Length == 0)
					InternalID = id;
			}
		}

		public SqlStringKey(RowReader reader)
			: base(reader) { }
		#endregion /***** Constructors *****/

		#region /****** Properties ******/
		/// <summary>
		/// Gets the value of a new record ID
		/// </summary>
		protected override string NewRecordID
		{
			get { return string.Empty; }
		}

		public override bool IsNewRecord
		{
			get { return base.IsNewRecord; }
			set
			{
				// Base resets ID when new record is true, and string keys shouldn't reset
				string idValue = ID;

				base.IsNewRecord = value;
				if (base.IsNewRecord)
					InternalID = idValue;
			}
		}

		public override string ID
		{
			get
			{ 
				if (InternalID == null)
					return string.Empty;

				return InternalID;
			}
			set { InternalID = value; }
		}
		#endregion /****** Properties ******/
	}
}